package com.example.javaui.component;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.*;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;

public class NeumorComponent extends Component implements Component.DrawTask {

    public NeumorComponent(Context context) {
        super(context);
        initView();
    }

    public NeumorComponent(Context context, AttrSet attrSet) {
        super(context, attrSet);
        initView();
    }

    public NeumorComponent(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        initView();
    }

    private void initView() {
        this.addDrawTask(this);
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {

        int width = getWidth();
        int height = getHeight();
        int shadowWidth = 40;
        int centerX = width / 2;
        int centerY = height / 2;
        int realWidth = width - shadowWidth * 2;
        int realHeight = height - shadowWidth * 2;

        canvas.drawRect(new RectFloat(shadowWidth, shadowWidth, realWidth + shadowWidth, realHeight + shadowWidth), newPaint(centerX, centerY, shadowWidth));

    }

    private static Paint newPaint(int centerX, int centerY, int shadowWidth) {

        Paint paint = new Paint();
        paint.setCornerPathEffectRadius(50);
        paint.setColor(new Color(Color.rgb(0xe4, 0xf0, 0xfa)));
        MaskFilter maskFilter = new MaskFilter(shadowWidth - 5, MaskFilter.Blur.SOLID);
        paint.setMaskFilter(maskFilter);
        return paint;

    }
}
